package cool.taomu.toolkit.service.client.kademlia.module

import com.google.inject.Inject
import cool.taomu.toolkit.service.kademlia.entity.Constant
import cool.taomu.toolkit.service.kademlia.entity.KPeerNode
import cool.taomu.toolkit.service.kademlia.service.KRoutingTable
import cool.taomu.toolkit.service.kademlia.utils.KademliaUtils
import java.io.File
import java.security.SecureRandom
import javax.inject.Named
import javax.inject.Provider
import org.slf4j.LoggerFactory

@Deprecated
class RoutingTableProvider implements Provider<KRoutingTable> {
	val static LOG = LoggerFactory.getLogger(RoutingTableProvider);

	@Inject(optional=true)
	@Named("taomu.kademlia.name")
	String name;

	@Inject(optional=true)
	@Named("taomu.kademlia.k")
	int k = 8;

	override get() {
		LOG.info("KRoutingTable创建");
		var localNode = new KPeerNode("localhost",18080);
		localNode.id = KademliaUtils.createNodeId();
		LOG.info("生成的本地节点信息:{}", localNode)
		 var torrent = new File(Constant.TORRENT_DOWNLOAD_PATH)
        if (!torrent.exists) {
            torrent.mkdirs
        }
		return new KRoutingTable();
	}
}
